function [ssss_symbols_0, ssss_symbols_1, ssss_time_domain_0, ssss_time_domain_1, ssss_indices_0, ssss_indices_1] = Function_Generate_SSS(slMode, NSLRB, NSLID, N_pss_cazac, NRBsc, cpLenR, NFFT, cp_Len_r12)
	%Create Secondary Sync Signals (36.211, 9.7.2)
            
	%% This function creates the secondary synch signals:
	if slMode == 0 % legacy LTE mode, not fully tested/supported yet
        nid_1 = floor(NSLID/3);
        num_nid1s = length(nid_1);
        nid_2 = mod(NSLID,3);                
 	elseif slMode > 0 % sidelink mode
      	nid_1 = mod(NSLID, 168);
        num_nid1s = length(nid_1);
    	nid_2 = floor(NSLID/168);
    end
  	% Initialization of output sequence matrix:
    ssss_symbols_0 = complex(zeros(N_pss_cazac-1, num_nid1s));
	ssss_symbols_1 = complex(zeros(N_pss_cazac-1, num_nid1s));
            
   	counter = 1;
	for jj = nid_1
        % Find parameters m0 and m1:
        q_hat = floor(jj/((N_pss_cazac-1)/2-1));
       	q = floor((jj + q_hat*(q_hat+1)/2)/((N_pss_cazac-1)/2-1));
    	m_hat = jj + q*(q+1)/2;
                
        m0 = mod(m_hat, (N_pss_cazac-1)/2);
        m1 = mod(m0 + floor(m_hat/((N_pss_cazac-1)/2)) + 1, (N_pss_cazac-1)/2);
                
        % Create x sequences for s_wave, c_wave and z:
        x1 = (zeros((N_pss_cazac-1)/2,1));
        x2 = (zeros((N_pss_cazac-1)/2,1));
        x3 = (zeros((N_pss_cazac-1)/2,1));
        x1(5) = 1;
        x2(5) = 1;
        x3(5) = 1;
                
        for ii = 1 : length(x1)-5
         	x1(5+ii) = mod(x1(ii+2)+x1(ii),2);
          	x2(5+ii) = mod(x2(ii+3)+x2(ii),2);
        	x3(5+ii) = mod(x3(ii+4)+x3(ii+2)+x3(ii+1)+x3(ii),2);
        end
                
        % Create s_wave sequence:
        s_wave = 1 - 2*x1;
                
        % Create s0_m0 and s1_m1:
        s0_m0 = circshift(s_wave(:), -m0);
        s1_m1 = circshift(s_wave(:), -m1);
                
        % create c_wave:
        c_wave = 1 - 2*x2;
                
        % Create z_wave:
        z_wave = 1 - 2*x3;
                
        % Create z1_m0 and z1_m1:
        n = 0:(N_pss_cazac-1)/2-1;
        z1_m0 = z_wave(mod(n + mod(m0,8), (N_pss_cazac-1)/2) + 1);
    	z1_m1 = z_wave(mod(n + mod(m1,8), (N_pss_cazac-1)/2) + 1);
                
       	% Create final sequences:
        seq_sub_0 = complex(zeros(N_pss_cazac-1, 1));
        seq_sub_1 = complex(zeros(N_pss_cazac-1, 1));
                
                
    	% Create c0 and c1:
     	c0 = circshift(c_wave, -(nid_2(counter)));
     	c1 = circshift(c_wave, -(nid_2(counter))-3);
                
        seq_sub_0(1:2:end) = s0_m0.*c0;
        seq_sub_1(1:2:end) = s1_m1.*c0;
                
        seq_sub_0(2:2:end) = s1_m1.*c1.*z1_m0;
        seq_sub_1(2:2:end) = s0_m0.*c1.*z1_m1;
                
        if (slMode == 1 || slMode == 2 )
        	ssss_symbols_0(:, counter) = sqrt(72/62)*seq_sub_0;
        	ssss_symbols_1(:, counter) = ssss_symbols_0(:, counter);
        elseif (slMode == 3 || slMode == 4 )
         	ssss_symbols_1(:, counter) = sqrt(72/62)*seq_sub_1;
        	ssss_symbols_0(:, counter) = ssss_symbols_1(:, counter);
      	elseif slMode == 0 % not fully supported yet
           	ssss_symbols_0(:, counter) = sqrt(72/62)*seq_sub_0;
            ssss_symbols_1(:, counter) = sqrt(72/62)*seq_sub_1;
        end
            counter = counter + 1;
    end
            
	%% Create SSSS indices
	Nsc = NSLRB*NRBsc;
            
	if slMode > 0 % sidelink mode
        if strcmp(cp_Len_r12, 'Normal')
            ssss_indices_0 = 7*Nsc + (4*Nsc+Nsc/2-(N_pss_cazac-1)/2+1: 4*Nsc+Nsc/2+(N_pss_cazac-1)/2);
         	ssss_indices_1 = 7*Nsc + (5*Nsc+Nsc/2-(N_pss_cazac-1)/2+1: 5*Nsc+Nsc/2+(N_pss_cazac-1)/2);
        elseif strcmp(cp_Len_r12, 'Extended')
         	ssss_indices_0 = 6*Nsc + (3*Nsc/2-(N_pss_cazac-1)/2+1: 3*Nsc/2+(N_pss_cazac-1)/2);
            ssss_indices_1 = 6*Nsc + (4*Nsc+Nsc/2-(N_pss_cazac-1)/2+1: 4*Nsc+Nsc/2+(N_pss_cazac-1)/2);
        end
	elseif slMode == 0 % legacy LTE mode, not fully tested/supported yet
        if strcmp(cp_Len_r12, 'Normal')
            ssss_indices_0 = (5*Nsc+Nsc/2-(N_pss_cazac-1)/2+1: 5*Nsc+Nsc/2+(N_pss_cazac-1)/2);
            ssss_indices_1 = ssss_indices_0;
        elseif strcmp(cp_Len_r12, 'Extended')
           	ssss_indices_0 = (4*Nsc+Nsc/2-(N_pss_cazac-1)/2+1: 4*Nsc+Nsc/2+(N_pss_cazac-1)/2);
            ssss_indices_1 = ssss_indices_0; % h.ssss_indices_1 = h.ssss_indices_0 kostas??
        end
    end
            
	%% Create time domain signal:
    ssss_time_domain_0 = Function_Create_Time_Domain_Signal(slMode, NFFT, N_pss_cazac, NSLRB, NRBsc, cpLenR, ssss_symbols_0);
	if slMode == 0 % legacy LTE mode, not fully tested/supported yet
        ssss_time_domain_1 = Function_Create_Time_Domain_Signal(slMode, NFFT, N_pss_cazac, NSLRB, NRBsc, cpLenR, ssss_symbols_1);
	elseif slMode > 0 % sidelink mode
    	ssss_time_domain_1 = ssss_time_domain_0;
	end
            
end % create_sss